$(function () {
var app = new Vue({
	el: '#app'
	,data:{
		queryIng:false
		,queryData:{activeFlag:'1',page:1,rows:50,totalNum:0}//查询条件
		,queryTaskData:{activeFlag:'1',page:1,rows:50,totalNum:0}//查询条件
		,datagrid:[]//数据列表数据
		,taskDatagrid:[]//数据列表数据
		,rules:[]
		,addProject:{}
		,addTask:{}
		,projectAddDialogVisible:false
		,taskAddDialogVisible:false
	}
	,methods:{
		init:function(){
			this.queryLibrary();
			this.queryTask();
		}
		,closeDialog:function(){
			app.projectAddDialogVisible = false;
		}
		,closeTaskDialog:function(){
			app.taskAddDialogVisible = false;
		}
		,openDialog:function(){
			app.projectAddDialogVisible = true;
			if(app.$refs['projectAddForm']){
				app.$refs['projectAddForm'].resetFields();
			}
		}
		,openTaskDialog:function(){
			app.taskAddDialogVisible = true;
			if(app.$refs['taskAddForm']){
				app.$refs['taskAddForm'].resetFields();
			}
		}
		,submitForm:function(){
			app.$refs['projectAddForm'].validate(function(res){
				if(res){
					//验证通过
					$.ajax({
						url : staticURL+'/testcase/caseProject/add',
						data : app.addProject,
						dataType : 'json',
						success : function(r) {
							if (r.success) {
								app.$message({showClose: true,
							          message: r.msg,
							          type: 'success',
							          position: 'top'});
								app.closeDialog();
								app.queryLibrary();
							} else {
								app.$message({showClose: true,
							          message: r.msg,
							          type: 'error',
							          position: 'top'});
							}
						}
					});
				}
			});
		}
		,submitTaskForm:function(){
			app.$refs['taskAddForm'].validate(function(res){
				if(res){
					//验证通过
					$.ajax({
						url : staticURL+'/testcase/testTask/add',
						data : app.addTask,
						dataType : 'json',
						success : function(r) {
							if (r.success) {
								app.$message({showClose: true,
									message: r.msg,
									type: 'success',
									position: 'top'});
								app.closeTaskDialog();
								app.queryTask();
							} else {
								app.$message({showClose: true,
									message: r.msg,
									type: 'error',
									position: 'top'});
							}
						}
					});
				}
			});
		}
		,queryLibrary:function(){
			var vm = this
			if(vm.queryIng){
				return;
			}
			vm.queryIng = true;
			$.ajax({
				url :staticURL+'/testcase/caseProject/datagrid.do',
				data : vm.queryData,
				dataType : 'json',
				success : function(json) {
					app.datagrid = json.rows;
					app.queryData.totalNum = json.total;
					app.queryIng = false;
				}
			});
		}
		,queryTask:function(){
			var vm = this
			$.ajax({
				url :staticURL+'/testcase/testTask/datagrid.do',
				data : vm.queryData,
				dataType : 'json',
				success : function(json) {
					app.taskDatagrid = json.rows;
					app.queryTaskData.totalNum = json.total;
				}
			});
		}
		,datagridSelect:function(row, event, column){
			window.location.href=staticURL+"/testcase/caseLibrary/goFrontendCaseLibrary?libraryCode="+row.id;
		}
		,taskDatagridSelect:function(row, event, column){
			window.location.href=staticURL+"/testcase/taskCase/goFrontendTaskCase?taskId="+row.id;
		}
		,handleSizeChange:function(val){
			app.queryData.rows=val;
			app.queryLibrary();
		}
		,handleCurrentChange:function(val){
			app.queryData.page=val;
			app.queryLibrary();
		}
		,handlePrevClick:function(val){
			app.queryData.page=val;
			app.queryLibrary();
		}
		,handleNextClick:function(val){
			app.queryData.page=val;
			app.queryLibrary();
		}
		,taskHandleSizeChange:function(val){
			app.queryTaskData.rows=val;
			app.queryTask();
		}
		,taskHandleCurrentChange:function(val){
			app.queryTaskData.page=val;
			app.queryTask();
		}
		,taskHandlePrevClick:function(val){
			app.queryTaskData.page=val;
			app.queryTask();
		}
		,taskHandleNextClick:function(val){
			app.queryTaskData.page=val;
			app.queryTask();
		}
		,goBackend:function(){
			window.open(staticURL+'/backend');
		}
	}
	,created: function () {
		this.init();
	},
});
});